<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- <ul>
        <li flg="../image/image1.png">
            <img src="" alt="">
        </li>
        <li flg="../image/image1.png">
            <img src="" alt="">
        </li>
        <li flg="../image/image1.png">
            <img src="" alt="">
        </li>
        <li flg="../image/image1.png">
            <img src="" alt="">
        </li>
        <li flg="../image/image1.png">
            <img src="" alt="">
        </li>
        <li flg="../image/image1.png">
            <img src="" alt="">
        </li>
        <li flg="../image/image1.png">
            <img src="" alt="">
        </li>
        <li flg="../image/image1.png">
            <img src="" alt="">
        </li>
        <li flg="../image/image1.png">
            <img src="" alt="">
        </li>
        <li flg="../image/image1.png">
            <img src="" alt="">
        </li>
        <li flg="../image/image1.png">
            <img src="" alt="">
        </li>
        <li flg="../image/image1.png">
            <img src="" alt="">
        </li>
        
    </ul>
    <script>
        // 懒加载:
        // 作用: 根据需求加载数据,减少数据请求,优化页面性能
        // 原理:
        //     遍历所有的li判断是否需要加载图片
        //     li 距离浏览器顶部的距离<=浏览器可视化宽度-被卷曲的宽度时显示图片
        var c = console.log.bind(document)
        var oli = document.getElementsByTagName('li')
        var img = document.getElementsByTagName('img')
        onscroll = function(){
            for(var i=0;i<oli.length;i++) {
                var a = document.documentElement.scrollTop + document.documentElement.clientHeight
                if(oli[i].offsetTop <= a){
                    if(img[i].src == oli[i].getAttribute('flg')) {
                        c('yes')
                    }else {
                        img[i].src = oli[i].getAttribute('flg')
                    }
                }
            }
        }
    </script> -->

    
</body>
</html>